data(crime): Lightly cleaned Houston crime from January 2010 to August 2010 geocoded with Google Maps by Houston Police Department, City of Houston
library(ggmap)
qmplot(lon, lat, data = crime)
Subset
# only violent crimes
violent_crimes <- subset(crime,
offense != "auto theft" &
offense != "theft" &
offense != "burglary"
)
# rank violent crimes
violent_crimes$offense <- factor(
violent_crimes$offense,
levels = c("robbery", "aggravated assault", "rape", "murder")
)
# restrict to downtown
violent_crimes <- subset(violent_crimes,
-95.39681 <= lon & lon <= -95.34188 &
29.73631 <= lat & lat <= 29.78400
)
theme_set(theme_bw())
qmplot(lon, lat, data = violent_crimes, colour = offense,
size = I(3.5), alpha = I(.6), legend = "topleft")
qmplot(lon, lat, data = violent_crimes, geom = c("point","density2d"))
qmplot(lon, lat, data = violent_crimes) + facet_wrap(~ offense)
qmplot(lon, lat, data = violent_crimes, extent = "panel") + facet_wrap(~ offense)
qmplot(lon, lat, data = violent_crimes, extent = "panel", colour = offense, darken = .4) +
facet_wrap(~ month)
data(seal): Vector field of seal movements This vector field was produced from the data described in Brillinger, D.R., Preisler, H.K., Ager, A.A. and Kie, J.G. “An exploratory data analysis (EDA) of the paths of moving animals”. J. Statistical Planning and Inference 122 (2004), 43-63, using the methods of Brillinger, D.R., “Learning a potential function from a trajectory”, Signal Processing Letters. December (2007).
qmplot(long, lat, xend = long + delta_long,
color = I("red"), yend = lat + delta_lat, data = seals, arrow = arrow(length=unit(0.1,"cm")),geom = "segment", zoom = 5)
qmplot(long, lat, xend = long + delta_long, maptype = "watercolor",
yend = lat + delta_lat, data = seals,arrow = arrow(length=unit(0.1,"cm")), geom = "segment", zoom = 6)
Subset the wind fields
s <- seq(1, 227, 8)
thinwind <- subset(wind,
lon %in% unique(wind$lon)[s] &
lat %in% unique(wind$lat)[s])
Add arrows
theme_set(theme_bw(18))
qmplot(lon, lat, data = thinwind, geom = "tile", fill = spd, alpha = spd,
legend = "bottomleft") +
geom_leg(aes(xend = lon + delta_lon, yend = lat + delta_lat), arrow = arrow(length=unit(0.1,"cm"))) + scale_fill_gradient2("Wind Speed\nand\nDirection",low = "green", mid = scales::muted("green"), high = "red") + scale_alpha("Wind Speed\nand\nDirection", range = c(.1, .75)) + guides(fill = guide_legend(), alpha = guide_legend())
library(ggmap)
#a simple example
murder <- subset(crime, offense == "murder")
qmplot(lon, lat, data = murder, colour = I('red'), size = I(3), darken = .3)
#The layered grammar of graphics
columbia <- "Columbia university in the city of new york"
qmap(columbia, zoom = 14)
qmap(columbia, zoom = 14, source = "osm")
## maptype arguments of get_map
set.seed(500)
df <- round(data.frame(
x = jitter(rep(-95.36, 50), amount = .3),
y = jitter(rep( 29.76, 50), amount = .3)
), digits = 2)
map <- get_googlemap('houston', markers = df, path = df, scale = 2)
ggmap(map, extent = 'device')
qmap(columbia, zoom = 14, source = "stamen", maptype = "watercolor")